﻿using AuthCenter.API.Application.Command.Account;
using AuthCenter.Domain.Account;
using AuthCenter.ErrorCode;
using AuthCenter.Intertructrue.Interface;
using MediatR;

namespace AuthCenter.API.Application.Handler.Account
{
    public class GetCityHandler : IRequestHandler<GetCityCommand,APIResult<List<CityModel>>>
    {
        private readonly IBaseRepository<CityModel> cityRepo;

        public GetCityHandler(IBaseRepository<CityModel> cityRepo)
        {
            this.cityRepo = cityRepo;
        }
        public Task<APIResult<List<CityModel>>> Handle(GetCityCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<CityModel>> result = new APIResult<List<CityModel>>();
            var res = cityRepo.GetAll().Where(x => x.IsDel == false&&x.ProvincesId==request.provincesId).ToList();
            result.Message = "显示成功";
            result.Code = APIEnum.Ok;
            result.Data = res;
            return Task.FromResult(result);
        }
    }
}
